package ph.com.gs3.formalistics.view.valueobjects.parsers;

import java.text.SimpleDateFormat;

import ph.com.gs3.formalistics.model.valueobjects.business.User;
import ph.com.gs3.formalistics.model.valueobjects.business.document.Document;
import ph.com.gs3.formalistics.model.valueobjects.business.form.Form;
import ph.com.gs3.formalistics.view.valueobjects.UserActionListViewItem;
import android.annotation.SuppressLint;

public class DocumentParser extends UserActionListViewItemParser {

	public static final String TAG = DocumentParser.class.getSimpleName();

	public static final String USER_ACTION_LIST_ITEM_DATE_FORMAT = "MMM d";

	@SuppressLint("SimpleDateFormat")
	public static SimpleDateFormat userActionListeItemDateFormatter = new SimpleDateFormat(
	        USER_ACTION_LIST_ITEM_DATE_FORMAT);

	public static UserActionListViewItem toUserActionListItem(Document document, Form form,
	        User documentAuthor, User currentlyActiveUser) {

		UserActionListViewItem actionItem = new UserActionListViewItem();

		// @formatter:off
		actionItem.documentDbId 	= document.getDbId();
		actionItem.documentWebId	= document.getWebId();
		actionItem.formWebId		= document.getFormWebId();
		actionItem.authorWebId		= document.getRequestorWebId();
		actionItem.server			= document.getServer();
		
		actionItem.header 			= form.getName();
		actionItem.subheader 		= documentAuthor.getDisplayName();
		actionItem.date 			= formatDate(document.getDateCreated());

		actionItem.contentsHeader	= "Tracking Number: " + document.getTrackingNumber();
		actionItem.contentsBody 	= generateUserActionListItemContentsFromFields(form, document.getFields());

		actionItem.footerHeader		= "Status:";
		actionItem.footerBody 		= document.getStatus();
		actionItem.imageURL 		= documentAuthor.getImageURL();
		
		actionItem.isStarred			= document.isStarred();
		actionItem.availableActions		= document.getAvailableActions();
		actionItem.showActionsButton	= document.getProcessorWebId().equalsIgnoreCase(Integer.toString(currentlyActiveUser.getWebId()));
		
		// @formatter:on

		return actionItem;

	}

}
